<!DOCTYPE html>
<html>
<head>
	<title>精准扶贫档案管理</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="jzfpsy.css">
	<link rel="shortcut icon" type="images/x-icon" href="images/favicon.ico">
	<script type="text/javascript" src="jquery.min.js"></script>
	<style type="text/css">
		.admin{
			position: relative;
			top:0px;
			left: -635px;
		}
	</style>
	<script>
	$(function(){
		//记录密码并输入
		function cookieDay(day){
			var date = new Date();
			date.setDate(date.getDate() + day)
			return date;
		}
		var arr = document.cookie.split(";");
		var obj ={}
		arr.forEach(function(item,index){
			obj[item.split("=")[0].replace(" ","")] = item.split("=")[1];

		})
		$(".sigin1").val(obj.username);
		$(".password1").val(obj.password);
		//是否记录密码
		$("#rem").click(function(){
			if($("#rem")[0].checked){
				var username = $(".sigin1").val();
				var password = $(".password1").val();
				document.cookie = `password=${password};expires= ${cookieDay(10)}`;
				document.cookie = `username=${username};expires= ${cookieDay(10)}`;
			}
		})
		//注册
		$(".register").click(function(){
			var arr = [];
			$(" .textz input").each(function(index,element){
				arr[index] = this.value;
			})
			$.ajax({
				url:"http://192.168.0.117:81/addData",
				data:{
					accountNumber:arr[0],
					passWord:arr[1],
				},
				success:function(data){
					// var data= JSON.parse(data)
						console.log(data)
					if(data == "error"){
						alert("注册失败，此账号已注册！")
					}
					else{
						alert("注册成功")
						window.location.href = "text/zhuceyemian.html"
					}
				},
				error:function(data){
					alert("注册失败，此账号已注册！")
					
				}
			})
			// 原生js请求
			// var http = new XMLHttpRequest();
			// http.open("GET","http://192.168.0.117:81/addData?accountnumber=" + arr[0] +"&password=" + arr[1],true);
			// http.send();
			// http.onreadystatechange = function(){
			// 	if(http.status == 200 && http.readyState == 4){
			// 		console.log(http.responseText);
			// 	}
			// }
		})
		//登录
		$(".sigin").click(function(){
			var arr = [];
			$("input").each(function(index,element){
				arr[index] = this.value;
			});
			$.ajax({
				url:"http://192.168.0.117:81/sigin",
				data:{
					accountNumber:arr[0],
					passWord:arr[1],
				},
				success:function(data){
					// var data = JSON.parse(data);
					console.log(data)
					if (data == 1) {
						alert("登录成功")
						window.location.href="text/xiugaixinxi.html"
					}
					else{
						alert("检查账号和密码！")
					}
				},
				error:function(){
					alert("检查账号和密码！")
				}
			})	
		})
		//管理员登录
		$(".admin").click(function(){
			var arr = [];
			$("input").each(function(index,element){
				arr[index] = this.value;
			});
			$.ajax({
				url:"http://192.168.0.117:81/admin",
				data:{
					accountNumber:arr[0],
					passWord:arr[1],
				},
				success:function(data){
					var data = JSON.parse(data);
					console.log(data)
					if (data == 1) {
						alert("登录成功")
						window.location.href="text/guanliyuan.html"
					}
					else{
						alert("检查账号和密码！")
					}
				},
				error:function(){
					alert("检查账号和密码！")
				}
			})
		})
	})
	</script>
</head>
<body>
	<div class="content">
		<div class="top">
			<img src="images/u=576006878,3397872292&fm=26&gp=0.jpg">
			<span class="mc">精准扶贫贫困户档案管理</span>
			<p class="topa">联系电话：0000-000000</p>
		</div>
		<div class="text">
			<img src="images/35ed0e9ea7352af8c461b33f426f092b.jpg">
			<div class="texts">
				<h1>登&nbsp;&nbsp;&nbsp;&nbsp;录</h1>
				<strong>请使用精准扶贫贫困户账号进行登录</strong>
			</div>
			<div class="textz">
				<img src="images/timg.jpg">
				<input class="sigin1" type="text" name="" placeholder="请输入登录账号">
				<input class="password1" type="password" name="" placeholder="请输入登录密码">
				<button class="sigin">登录</button>
				<button class="register">注册</button>
				<button class="admin">管理员登录</button>
			</div>
			<div class="check" style="position: relative;right: -460px;
			bottom: -24px;color:yellow;">
				<input type="checkbox" name="" id="rem">：记录账号和密码
			</div>
		</div>
		<div class="bottom"><strong>精准扶贫贫困户档案管理系统</strong><span class="zy">注意：请牢记个人账号和密码!</span></div>
	</div>
</body>
</html>